package com.ruoyi.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.system.domain.SysMenu;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class TreeListMenu implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long menuId;
    private String name;
    private Long parentId;
    private Integer orderNum;
    private String path;
    private String component;
    private String query;
    private Integer isFrame;
    private String isCache;
    private String menuType;
    private String visible;
    private String status;
    private String perms;
    private String icon;
    private String access;
    private Integer hideInMenu;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeListMenu> children;

    public TreeListMenu(SysMenu menu) {
        this.id = menu.getMenuId();
        this.menuId = menu.getMenuId();
        this.name = menu.getName();
        this.parentId = menu.getParentId();
        this.orderNum = menu.getOrderNum();
        this.path = menu.getPath();
        this.component = menu.getComponent();
        this.query = menu.getQuery();
        this.isFrame = menu.getIsFrame();
        this.isCache = menu.getIsCache();
        this.menuType = menu.getMenuType();
        this.visible = menu.getVisible();
        this.status = menu.getStatus();
        this.perms = menu.getPerms();
        this.icon = menu.getIcon();
        this.access = menu.getAccess();
        this.hideInMenu = menu.getHideInMenu();
        if (menu.getChildren() != null) {
            this.children = menu.getChildren().stream().map(TreeListMenu::new).collect(Collectors.toList());
        }
    }
}
